import { PageConfig } from 'next';
import anylogger from 'anylogger';
import '@mmstudio/an000042';
import an48 from '@mmstudio/an000048';
import { tbcurriculum } from '../../../../atoms/db';

const logger = anylogger('pages/api/basicinformation/curriculum/delete.api');

export type Result = {
	ok: boolean;
	message: string;
};

export type Query = {
	/**
	 * id
	 */
	id: string;
}

/**
 * 专业管理-删除
 */
const handler = an48<Result>();

handler.delete(async (req, res) => {
	try {
		logger.debug('msg body:', req.body);
		//解析查询条件
		const { id } = req.body as Query;
		//删除数据
		if (!id) {
			res.status(200).json({
				ok: false,
				message: 'id不能为空'
			});
			return;
		}
		await tbcurriculum().del().where({ curriculum_id: id });
		res.status(200).json({ ok: true, message: '' });
	} catch (error) {
		logger.error(error);
		logger.trace(error);
		res.status(200).json({ ok: false, message: (error as Error).message });
	}
});

export const config = {} as PageConfig;

export default handler;
